package com.ruoyi.web.controller.prevention;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.PersonPosition;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.YnStatusEnum;
import com.ruoyi.common.utils.DateToUtils;
import com.ruoyi.common.utils.PrcentageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.entity.*;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 统计
 * http://192.168.18.158:39080/dev-api/preventionPlanTask/countTop
 *
 * @since 2022-12-17 13:22:34
 */
@Slf4j
@RestController
@RequestMapping("preventionPlanTask")
public class PreventionPlanTaskCountController extends BaseController {
    @Resource
    private AppCreateJobBillService appCreateJobBillService;
    @Resource
    private PreventionPlanTaskService preventionPlanTaskService;
    @Resource
    private PreventionCheckTaskConfigService preventionCheckTaskConfigService;
    @Resource
    private PreventionHiddenRegisterService preventionHiddenRegisterService;
    @Resource
    private PreventionHiddenRegisterMapper preventionHiddenRegisterMapper;
    @Resource
    private PreventionCheckTaskConfigMapper preventionCheckTaskConfigMapper;
    @Resource
    private PreventionCheckTaskMapper preventionCheckTaskMapper;
    @Resource
    private PreventionDeviceService preventionDeviceService;
    @Resource
    private PreventionSecurityRiskMapper preventionSecurityRiskMapper;
    @Resource
    private PreventionHiddenInfoRecordMapper preventionHiddenInfoRecordMapper;
    @Resource
    private InspectionPlanTaskMapper inspectionPlanTaskMapper;
    @Resource
    private InspectionPlanMapper inspectionPlanMapper;
    @Resource
    private PreventionDeviceMapper preventionDeviceMapper;
    @Resource
    private PreventionPlanTaskMapper preventionPlanTaskMapper;
    @Resource
    private SysMonitorMapper sysMonitorMapper;
    @Resource
    private EnterpriseBasicMapper enterpriseBasicMapper;
    @Resource
    private KeyAlertMapper keyAlertMapper;
    @Resource
    private EnclosureAlertMapper enclosureAlertMapper;
    @Resource
    private SecurityStaffCertificateRecordMapper securityStaffCertificateRecordMapper;
    @Resource
    private SysDeptMapper sysDeptMapper;
    @Resource
    private PreventionSecurityRiskService preventionSecurityRiskService;
    @Resource
    private PreventionAlertMapper preventionAlertMapper;
    @Resource
    private SysDutyUserService sysDutyUserService;

    /**
     * 首页_统计我的任务完成情况 以及 总的任务完成表情况
     */
    @GetMapping("/toCountMyTask")
    public AjaxResult toCountMyTask() {
        String checkUserName = SecurityUtils.getLoginUser().getUser().getNickName();
        //String checkUserName = "陈基惠";
        Map<String, Object> map = new HashMap<>();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        int dpc = preventionPlanTaskService.getDpc(checkUserName);
        int ycs = preventionPlanTaskService.getYcs(checkUserName);
        int ypc = preventionPlanTaskService.getYpc(checkUserName);
        int alls = preventionPlanTaskService.getAlls(checkUserName);
        int dzgyh = preventionHiddenRegisterService.getDzgyh(checkUserName);
        /*int ypc = 1;
        int alls = 10;*/
        map.put("待排查", dpc);
        map.put("已排查", ypc);
        map.put("已超时", ycs);
        map.put("待整改隐患", dzgyh);
        if (0 == alls) {
            map.put("排查任务完成率", "0.00%");
        } else {
            map.put("排查任务完成率", prcentageUtils.percent(ypc, alls));
        }
        return AjaxResult.success(map);
    }


    @GetMapping("countUnit")
    public AjaxResult countUnit() {

        List<PreventionSecurityRisk> preventionSecurityRiskList = preventionSecurityRiskMapper.queryAllUnit(null, null, null);

        return AjaxResult.success(preventionSecurityRiskList);
    }

    /**
     * 首页_统计单位运行效果
     */
    @GetMapping("/toCountUnit")
    public AjaxResult toCountUnit(String startTime, String endTime) {
        List list = new ArrayList();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        PreventionCountVO preventionCountVO = new PreventionCountVO();
        Map<String, Integer> map = new HashMap<>();
       /* // 上周
        DateFormat dateformat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String startTime = dateformat.format(DateToUtils.getBeginDayOfLastWeek());
        String endTime = dateformat.format(DateToUtils.getEndDayOfLastWeek());*/
        Integer you = 0;
        Integer liang = 0;
        Integer zhong = 0;
        Integer cha = 0;
        List<SysDept> sysDepts = sysDeptMapper.selectDeptList(new SysDept());
        if (!CollectionUtils.isEmpty(sysDepts)) {
            for (SysDept sysDept : sysDepts) {
                if (sysDept.getParentId() == 0) {
                    continue;
                }
                PreventionHiddenRegisterHiddenCountVO vo = new PreventionHiddenRegisterHiddenCountVO();
                UnitCountVO unitCountVO = new UnitCountVO();
                Integer ywcCount = this.preventionCheckTaskConfigMapper.queryYwcCount(sysDept.getDeptName(), startTime, endTime, null);
                Integer sjCount = this.preventionCheckTaskConfigMapper.querySjCount(sysDept.getDeptName(), startTime, endTime, null);
                Integer hiddenCount = this.preventionHiddenRegisterMapper.queryHiddenCount(sysDept.getDeptName(), startTime, endTime);
                Integer hiddenZgCount = this.preventionHiddenRegisterMapper.queryHiddenZgCount(sysDept.getDeptName(), startTime, endTime);
                // B
                if (0 == sjCount) {
                    vo.setTaskWcRate("100.00%");
                } else {
                    vo.setTaskWcRate(prcentageUtils.percent(ywcCount, sjCount));
                }
                // C
                if (0 == hiddenCount) {
                    vo.setHiddenZgRate("100.00%");
                } else {
                    vo.setHiddenZgRate(prcentageUtils.percent(hiddenZgCount, hiddenCount));
                }
                vo.getACountRate();

                String taskTemp = vo.getTaskWcRate().replace("%", "");
                float taskWcRateTemp = Float.valueOf(taskTemp) / 100;

                String hiddenTemp = vo.getHiddenZgRate().replace("%", "");
                float hiddenZgRateTemp = Float.valueOf(hiddenTemp) / 100;
                // 分数
                BigDecimal totalScore = new BigDecimal(0);
                totalScore = totalScore.add(new BigDecimal(taskWcRateTemp).multiply(new BigDecimal(50)).setScale(2, RoundingMode.HALF_UP));
                totalScore = totalScore.add(new BigDecimal(hiddenZgRateTemp).multiply(new BigDecimal(50).setScale(2, RoundingMode.HALF_UP)));
                String YxConditionTemp = "";
                if (totalScore.compareTo(new BigDecimal(90)) == 1) {
                    YxConditionTemp = "优";
                    you++;
                }
                if (totalScore.compareTo(new BigDecimal(80)) == 0 && totalScore.compareTo(new BigDecimal(90)) != 1) {
                    YxConditionTemp = "良";
                    liang++;
                }
                if (totalScore.compareTo(new BigDecimal(70)) == 0 && totalScore.compareTo(new BigDecimal(80)) != 1) {
                    YxConditionTemp = "中";
                    zhong++;
                }
                if (totalScore.compareTo(new BigDecimal(70)) == -1) {
                    YxConditionTemp = "差";
                    cha++;
                }
                unitCountVO.setName(sysDept.getDeptName());
                unitCountVO.setYxCondition(YxConditionTemp);
                list.add(unitCountVO);
            }
        }
        map.put("优", you);
        map.put("良", liang);
        map.put("中", zhong);
        map.put("差", cha);
        preventionCountVO.setMap(map);
        preventionCountVO.setList(list);
        return AjaxResult.success(preventionCountVO);
    }

    /**
     * 首页_统计上周任务排查情况
     */
    @GetMapping("/toCountTaskSituation")
    public AjaxResult toCountTaskSituation() {
        String start = DateUtil.beginOfWeek(DateUtil.lastWeek()).toString("yyyy-MM-dd HH:mm:ss");
        String end = DateUtil.endOfWeek(DateUtil.lastWeek()).toString("yyyy-MM-dd HH:mm:ss");
        List<PreventionCheckTaskConfigCountVO> arrayList = preventionCheckTaskConfigMapper.countDept(start, end);
        return AjaxResult.success(arrayList);
    }

    /**
     * 首页_统计隐患整改提醒
     */
    @GetMapping("/toCountHiddenRemind")
    public AjaxResult toCountHiddenRemind() {
        String checkUserName = SecurityUtils.getLoginUser().getUser().getNickName();
        List<PreventionCheckTaskConfigCountVO> list = preventionHiddenRegisterService.getToCountHiddenRemind(checkUserName);
        return AjaxResult.success(list);
    }

    /**
     * 首页_统计隐患整改情况
     */
    @GetMapping("/toCountHiddenCondition")
    public AjaxResult toCountHiddenCondition() {
        String checkUserName = SecurityUtils.getLoginUser().getUser().getNickName();
        List<PreventionCheckTaskConfigCountVO> list = preventionHiddenRegisterService.getToCountHiddenCondition(checkUserName);
        return AjaxResult.success(list);
    }

    /**
     * 首页_统计上周隐患整改率
     */
    @GetMapping("/toCountHiddenRate")
    public AjaxResult toCountHiddenRate() {
        String checkUserName = SecurityUtils.getLoginUser().getUser().getNickName();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String beginDayOfLastWeek = dateformat.format(DateToUtils.getBeginDayOfLastWeek());
        String endDayOfLastWeek = dateformat.format(DateToUtils.getEndDayOfLastWeek());
        List<PreventionCheckTaskConfigCountVO> arrayList = new ArrayList<>();
        // 查询 全部
        List<PreventionCheckTaskCountStateVO> allList = preventionCheckTaskConfigService.getToAllCountHiddenRate(checkUserName, beginDayOfLastWeek, endDayOfLastWeek);
        // 查询 待整改
        List<PreventionCheckTaskCountStateVO> oneList = preventionCheckTaskConfigService.getToCountHiddenRate(checkUserName, beginDayOfLastWeek, endDayOfLastWeek);
        if (!CollectionUtils.isEmpty(allList)) {
            for (PreventionCheckTaskCountStateVO allStateVO : allList) {
                if (!CollectionUtils.isEmpty(oneList)) {
                    for (PreventionCheckTaskCountStateVO oneStateVO : oneList) {
                        PreventionCheckTaskConfigCountVO taskConfigCountVO = new PreventionCheckTaskConfigCountVO();
                        if (allStateVO.getName().contains(oneStateVO.getName())) {
                            oneStateVO.setCount(prcentageUtils.percentTwo(Integer.valueOf(oneStateVO.getCount()), Integer.valueOf(allStateVO.getCount())));
                            taskConfigCountVO.setName(oneStateVO.getName());
                            taskConfigCountVO.setCount(oneStateVO.getCount());
                            arrayList.add(taskConfigCountVO);
                            break;
                        }
                    }
                } else {
                    arrayList = checkAll(checkUserName);
                    break;
                }
            }
        } else {
            arrayList = checkAll(checkUserName);
        }
        return AjaxResult.success(arrayList);
    }

    @GetMapping("/toCountDeptHiddenPC")
    public AjaxResult toCountDeptHiddenPC(PreventionHiddenRegisterCountVO preventionHiddenRegisterCountVO) {
        List<PreventionCheckTaskConfigCountVO> list = preventionHiddenRegisterService.getToCountDeptHiddenPC(preventionHiddenRegisterCountVO);
        if (CollectionUtils.isEmpty(list)) {
            list = getToCountDeptAll();
        }
        return AjaxResult.success(list);
    }

    /**
     * 按部门统计_隐患整改
     */
    @GetMapping("/toCountDeptHiddenZG")
    public AjaxResult toCountDeptHiddenZG(PreventionHiddenRegisterCountVO preventionHiddenRegisterCountVO) {
        List<PreventionCheckTaskConfigCountVO> arrayList = new ArrayList<>();
        List<PreventionCheckTaskConfigCountVO> deptAll = preventionHiddenRegisterService.getToCountHiddenDeptAll();
        List<PreventionCheckTaskConfigCountVO> list = preventionHiddenRegisterService.getToCountDeptHiddenZG(preventionHiddenRegisterCountVO);
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        if (!CollectionUtils.isEmpty(deptAll)) {
            for (PreventionCheckTaskConfigCountVO vo : deptAll) {
                if (!CollectionUtils.isEmpty(list)) {
                    for (PreventionCheckTaskConfigCountVO taskConfigCountVO : list) {
                        PreventionCheckTaskConfigCountVO countVO = new PreventionCheckTaskConfigCountVO();
                        if (vo.getName().contains(taskConfigCountVO.getName())) {
                            taskConfigCountVO.setCount(prcentageUtils.percentTwo(Integer.valueOf(taskConfigCountVO.getCount()), Integer.valueOf(vo.getCount())));
                            countVO.setName(taskConfigCountVO.getName());
                            countVO.setCount(taskConfigCountVO.getCount());
                            arrayList.add(countVO);
                            break;
                        }
                    }
                } else {
                    arrayList = getToCountDeptAll();
                }
            }
        } else {
            arrayList = getToCountDeptAll();
        }
        return AjaxResult.success(arrayList);
    }

    /**
     * 隐患排查治理统计
     */
    @GetMapping("/getCheckHiddenCount")
    public AjaxResult getCheckHiddenCount(String startTime, String endTime) {
        List list = new ArrayList();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        // 上周
        DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (StrUtil.isEmpty(startTime)) {
            startTime = dateformat.format(DateToUtils.getBeginDayOfLastWeek());
        }
        if (StrUtil.isEmpty(startTime)) {
            endTime = dateformat.format(DateToUtils.getEndDayOfLastWeek());
        }
        List<PreventionSecurityRisk> preventionSecurityRiskList = preventionSecurityRiskMapper.queryAllByDept();
        if (CollUtil.isNotEmpty(preventionSecurityRiskList) && preventionSecurityRiskList.size() == 1) {
            PreventionSecurityRisk preventionSecurityRisk1 = new PreventionSecurityRisk();
            preventionSecurityRisk1.setDeptName(preventionSecurityRiskList.get(0).getDeptName());
            preventionSecurityRisk1.setDeptUserName("总计");
            preventionSecurityRiskList.add(preventionSecurityRisk1);
        } else {
            PreventionSecurityRisk preventionSecurityRisk1 = new PreventionSecurityRisk();
            preventionSecurityRiskList.add(preventionSecurityRisk1);
        }
        PreventionHiddenRegisterHiddenCountVO all = new PreventionHiddenRegisterHiddenCountVO();
        for (PreventionSecurityRisk preventionSecurityRisk : preventionSecurityRiskList) {
            PreventionHiddenRegisterHiddenCountVO vo = new PreventionHiddenRegisterHiddenCountVO();
            // 排查任务应完成数
            Integer ywcCount = this.preventionCheckTaskConfigMapper.querySjCount(preventionSecurityRisk.getDeptName(), startTime, endTime, null);
            // 排查任务实际完成数
            Integer sjCount = this.preventionCheckTaskConfigMapper.queryYwcCount(preventionSecurityRisk.getDeptName(), startTime, endTime, null);
            // 隐患数
            Integer hiddenCount = this.preventionHiddenRegisterMapper.queryHiddenCount(preventionSecurityRisk.getDeptName(), startTime, endTime);
            // 隐患整改数
            Integer hiddenZgCount = this.preventionHiddenRegisterMapper.queryHiddenZgCount(preventionSecurityRisk.getDeptName(), startTime, endTime);
            // B 排查任务完成率
            if (0 == sjCount && ywcCount==0) {
                vo.setTaskWcRate("100.00%");
            } else if (ywcCount==0) {
                vo.setTaskWcRate("0%");
            } else {
                vo.setTaskWcRate(prcentageUtils.percent(sjCount, ywcCount));
            }
            // C 隐患整改率
            if (0 == hiddenCount && hiddenZgCount == 0) {
                vo.setHiddenZgRate("100.00%");
            } else if (0 == hiddenCount) {
                vo.setHiddenZgRate("0%");
            } else {
                vo.setHiddenZgRate(prcentageUtils.percent(hiddenZgCount, hiddenCount));
            }
            String taskTemp = vo.getTaskWcRate().replace("%", "");
            float taskWcRateTemp = Float.valueOf(taskTemp) / 100;

            String hiddenTemp = vo.getHiddenZgRate().replace("%", "");
            float hiddenZgRateTemp = Float.valueOf(hiddenTemp) / 100;
            // 分数
            BigDecimal totalScore = new BigDecimal(0);
            totalScore = totalScore.add(new BigDecimal(taskWcRateTemp).multiply(new BigDecimal(50)).setScale(2, RoundingMode.HALF_UP));
            totalScore = totalScore.add(new BigDecimal(hiddenZgRateTemp).multiply(new BigDecimal(50).setScale(2, RoundingMode.HALF_UP)));
            String YxConditionTemp = "";
            if (totalScore.compareTo(new BigDecimal(90)) == 1) {
                YxConditionTemp = "优";
            }
            if (totalScore.compareTo(new BigDecimal(80)) == 0 && totalScore.compareTo(new BigDecimal(90)) != 1) {
                YxConditionTemp = "良";
            }
            if (totalScore.compareTo(new BigDecimal(70)) == 0 && totalScore.compareTo(new BigDecimal(80)) != 1) {
                YxConditionTemp = "中";
            }
            if (totalScore.compareTo(new BigDecimal(70)) == -1) {
                YxConditionTemp = "差";
            }
            vo.setTaskYwcCount(ywcCount);
            vo.setTaskSjCount(sjCount);
            vo.setHiddenCount(hiddenCount);
            vo.setHiddenZgCount(hiddenZgCount);
            vo.setFsCount(totalScore);
            vo.setYxCondition(YxConditionTemp);
            List<DutyUserCountVO> dutyUserCountVOS = sysDutyUserService.toCountSysDuty(startTime, endTime);
            DutyUserCountVO dutyUserCountVO = dutyUserCountVOS.get(dutyUserCountVOS.size() - 1);
            String zrate = dutyUserCountVO.getZrate();
//            if (!zrate.equals("100.00%")) {
//                vo.setFsCount(vo.getFsCount().subtract(new BigDecimal("10")));
//            }
//            String jrate = dutyUserCountVO.getJrate();
//            if (!jrate.equals("100.00%")) {
//                vo.setFsCount(vo.getFsCount().subtract(new BigDecimal("5")));
//            }
//            String crate = dutyUserCountVO.getCrate();
//            if (!crate.equals("100.00%")) {
//                vo.setFsCount(vo.getFsCount().subtract(new BigDecimal("5")));
//            }
            if (vo.getFsCount().compareTo(BigDecimal.valueOf(0)) == -1) {
                vo.setFsCount(BigDecimal.valueOf(0));
            }
            if (StringUtils.isEmpty(preventionSecurityRisk.getDeptUserName())) {
                vo.setDeptName("总计");
                Integer imei = preventionCheckTaskConfigMapper.countImei(null,startTime, endTime);
                long count = preventionDeviceMapper.count(new PreventionDevice());
                vo.setImei(imei.toString());
                if (imei < count) {
                    vo.setFsCount(BigDecimal.valueOf(0));
                }
                BeanUtils.copyBeanProp(all, vo);
            } else {
                Integer imei = preventionCheckTaskConfigMapper.countImei(preventionSecurityRisk.getDeptName(),startTime, endTime);
                vo.setImei(imei.toString());
                vo.setDeptName(preventionSecurityRisk.getDeptName());
                list.add(vo);
            }
        }
        list.add(all);
        return AjaxResult.success(list);
    }

    @Log(title = "隐患排查治理统计部门(", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDept")
    public void exportDept(HttpServletResponse response, String startTime, String endTime) {
        List data = (List) getCheckHiddenCount(startTime, endTime).get("data");
        ExcelUtil<PreventionHiddenRegisterHiddenCountVO> util = new ExcelUtil<>(PreventionHiddenRegisterHiddenCountVO.class);
        util.exportExcel(response, data, "隐患排查治理统计部门(");
    }

    @Log(title = "隐患排查治理统计岗位(", businessType = BusinessType.EXPORT)
    @PostMapping("/exportPost")
    public void exportPost(HttpServletResponse response, String startTime, String endTime) {
        List data = (List) getPostCheckHiddenCount(startTime, endTime).get("data");
        ExcelUtil<PreventionHiddenRegisterHiddenCountVO> util = new ExcelUtil<>(PreventionHiddenRegisterHiddenCountVO.class);
        util.exportExcel(response, data, "隐患排查治理统计岗位(");
    }


    /**
     * 岗位机制运行统计
     */
    @GetMapping("/getPostCheckHiddenCount")
    public AjaxResult getPostCheckHiddenCount(String startTime, String endTime) {
        List list = new ArrayList();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        // 上周
        DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (StrUtil.isEmpty(startTime)) {
            startTime = dateformat.format(DateToUtils.getBeginDayOfLastWeek());
        }
        if (StrUtil.isEmpty(startTime)) {
            endTime = dateformat.format(DateToUtils.getEndDayOfLastWeek());
        }
        List<PreventionSecurityRisk> preventionSecurityRiskList = preventionSecurityRiskMapper.queryAllByPost();
        PreventionSecurityRisk preventionSecurityRisk1 = new PreventionSecurityRisk();
        preventionSecurityRiskList.add(preventionSecurityRisk1);
        PreventionHiddenRegisterHiddenCountVO all = new PreventionHiddenRegisterHiddenCountVO();
        for (PreventionSecurityRisk preventionSecurityRisk : preventionSecurityRiskList) {
            PreventionHiddenRegisterHiddenCountVO vo = new PreventionHiddenRegisterHiddenCountVO();
            Integer ywcCount = this.preventionCheckTaskConfigMapper.querySjCount(null, startTime, endTime, preventionSecurityRisk.getDeptUserName());
            Integer sjCount = this.preventionCheckTaskConfigMapper.queryYwcCount(null, startTime, endTime, preventionSecurityRisk.getDeptUserName());
            Integer hiddenCount = this.preventionHiddenRegisterMapper.queryPostHiddenCount(preventionSecurityRisk.getDeptUserName(), startTime, endTime);
            Integer hiddenZgCount = this.preventionHiddenRegisterMapper.queryPostHiddenZgCount(preventionSecurityRisk.getDeptUserName(), startTime, endTime);
            // B
            if (0 == sjCount && ywcCount==0) {
                vo.setTaskWcRate("100.00%");
            } else if (ywcCount==0) {
                vo.setTaskWcRate("0%");
            } else {
                vo.setTaskWcRate(prcentageUtils.percent(sjCount, ywcCount));
            }
            // C
            if (0 == hiddenCount && hiddenZgCount == 0) {
                vo.setHiddenZgRate("100.00%");
            } else if (0 == hiddenCount) {
                vo.setHiddenZgRate("0%");
            } else {
                vo.setHiddenZgRate(prcentageUtils.percent(hiddenZgCount, hiddenCount));
            }

            String taskTemp = vo.getTaskWcRate().replace("%", "");
            float taskWcRateTemp = Float.valueOf(taskTemp) / 100;

            String hiddenTemp = vo.getHiddenZgRate().replace("%", "");
            float hiddenZgRateTemp = Float.valueOf(hiddenTemp) / 100;
            // 分数
            BigDecimal totalScore = new BigDecimal(0);
            totalScore = totalScore.add(new BigDecimal(taskWcRateTemp).multiply(new BigDecimal(50)).setScale(2, RoundingMode.HALF_UP));
            totalScore = totalScore.add(new BigDecimal(hiddenZgRateTemp).multiply(new BigDecimal(50).setScale(2, RoundingMode.HALF_UP)));
            String YxConditionTemp = "";
            if (totalScore.compareTo(new BigDecimal(90)) == 1) {
                YxConditionTemp = "优";
            }
            if (totalScore.compareTo(new BigDecimal(80)) == 0 && totalScore.compareTo(new BigDecimal(90)) != 1) {
                YxConditionTemp = "良";
            }
            if (totalScore.compareTo(new BigDecimal(70)) == 0 && totalScore.compareTo(new BigDecimal(80)) != 1) {
                YxConditionTemp = "中";
            }
            if (totalScore.compareTo(new BigDecimal(70)) == -1) {
                YxConditionTemp = "差";
            }
            vo.setTaskYwcCount(ywcCount);
            vo.setTaskSjCount(sjCount);
            vo.setHiddenCount(hiddenCount);
            vo.setHiddenZgCount(hiddenZgCount);
            vo.setFsCount(totalScore);
            vo.setYxCondition(YxConditionTemp);
            if (StringUtils.isEmpty(preventionSecurityRisk.getDeptUserName())) {
                vo.setDeptName("总计");
                List<DutyUserCountVO> dutyUserCountVOS = sysDutyUserService.toCountSysDuty(startTime, endTime);
                DutyUserCountVO dutyUserCountVO = dutyUserCountVOS.get(dutyUserCountVOS.size() - 1);
                String zrate = dutyUserCountVO.getZrate();
//                if (!zrate.equals("100.00%")) {
//                    vo.setFsCount(vo.getFsCount().subtract(new BigDecimal("10")));
//                }
//                String jrate = dutyUserCountVO.getJrate();
//                if (!jrate.equals("100.00%")) {
//                    vo.setFsCount(vo.getFsCount().subtract(new BigDecimal("5")));
//                }
//                String crate = dutyUserCountVO.getCrate();
//                if (!crate.equals("100.00%")) {
//                    vo.setFsCount(vo.getFsCount().subtract(new BigDecimal("5")));
//                }
                Integer imei = preventionCheckTaskConfigMapper.countImei(null,startTime, endTime);
                long count = preventionDeviceMapper.count(new PreventionDevice());
                if (imei < count) {
                    vo.setFsCount(BigDecimal.valueOf(0));
                    vo.setImei(imei.toString());
                } else {
                    vo.setImei(imei.toString());
                }
                if (vo.getFsCount().compareTo(BigDecimal.valueOf(0)) == -1) {
                    vo.setFsCount(BigDecimal.valueOf(0));
                }
                BeanUtils.copyBeanProp(all, vo);
            } else {
                vo.setDeptName(preventionSecurityRisk.getDeptUserName());
                list.add(vo);
            }
        }
        list.add(all);
        return AjaxResult.success(list);
    }


    /**
     * 三维_分析单元数量_风险事件数量
     */
    @GetMapping("/swDyCountAndSjCount")
    public AjaxResult swDyCountAndSjCount() {
        List<PreventionCheckTaskConfigCountVO> dyCount = preventionSecurityRiskMapper.swDyCountAndSjCount();
        return AjaxResult.success(dyCount);
    }

    /**
     * 三维_风险分析集合
     */
    @GetMapping("/sWfxfxList")
    public AjaxResult sWfxfxList() {
        List<String> list = preventionSecurityRiskMapper.sWfxfxList();
        return AjaxResult.success(list);
    }

    /**
     * 三维_管控措施数量_隐患排查数量
     */
    @GetMapping("/swGkCountAndYhCount")
    public AjaxResult swGkCountAndYhCount(String analysisUnit) {
        List dyCount1 = preventionDeviceService.swGkCountAndYhCount(analysisUnit);
        return AjaxResult.success(dyCount1);
    }

    /**
     * 三维_隐患统计（一般、重大）
     */
    @GetMapping("/sWYhYbAndZdCount")
    public AjaxResult sWYhYbAndZdCount() {
        List<PreventionCheckTaskCountVO> allList = preventionHiddenRegisterMapper.sWYhYbAndZdCountTemp();
        return AjaxResult.success(allList);
    }

    /**
     * 三维_隐患统计（月份一般、重大）
     */
    @GetMapping("/sWYearCount")
    public AjaxResult sWYearCount() {
        List allList = new ArrayList<>();
        List<String> yearList = preventionHiddenRegisterMapper.getListAllMonth();
        if (!CollectionUtils.isEmpty(yearList)) {
            for (String month : yearList) {
                List<PreventionHiddenRegisterTimeVO> voList = preventionHiddenRegisterMapper.getYhYbAndZdCountTemp(month);
                if (!CollectionUtils.isEmpty(voList)) {
                    for (PreventionHiddenRegisterTimeVO registerTimeVO : voList) {
                        PreventionHiddenRegisterTimeVO vo = new PreventionHiddenRegisterTimeVO();
                        vo.setMonth(month.substring(5, 7) + "月");
                        vo.setCreateTime(month);
                        vo.setYbCount(registerTimeVO.getYbCount());
                        vo.setZdCount(registerTimeVO.getZdCount());
                        allList.add(vo);
                    }
                }
            }
        }
        return AjaxResult.success(allList);
    }

    /**
     * 三维_巡检点位数量_巡检路线数量_巡检计划数量
     */
    @GetMapping("/swDwAndLxAndJhCount")
    public AjaxResult swDwAndLxAndJhCount() {
        List<PreventionCheckTaskCountVO> lxAndJhCount = inspectionPlanMapper.swDwAndLxAndJhCount();
        return AjaxResult.success(lxAndJhCount);
    }

    /**
     * 三维_发现隐患的巡检记录（列表）
     */
    @GetMapping("/swHiddenList")
    public TableDataInfo swHiddenList() {
        startPage();
        List<InspectionPlanTaskListVO> voList = new ArrayList<>();
        List<PreventionHiddenInfoRecord> list = preventionHiddenInfoRecordMapper.queryAllByLimit(null);
        if (!CollectionUtils.isEmpty(list)) {
            for (PreventionHiddenInfoRecord infoRecord : list) {
                InspectionPlanTask voById = inspectionPlanTaskMapper.queryById(infoRecord.getInspectionPlanTaskId());
                if (!ObjectUtils.isEmpty(voById)) {
                    InspectionPlan inspectionPlan = inspectionPlanMapper.queryById(voById.getPlanId());
                    if (!ObjectUtils.isEmpty(inspectionPlan)) {
                        InspectionPlanTaskListVO vo = new InspectionPlanTaskListVO();
                        vo.setPlanName(inspectionPlan.getPlanName());
                        vo.setCheckTime(infoRecord.getCreateTime());
                        vo.setCheckUserName(infoRecord.getCreateUser());
                        voList.add(vo);
                    }
                }
            }
        }
        return getDataTable(voList);
    }

    /**
     * 统计三率_排查任务完成率_隐患整改率_风险分析完成率
     */
    @GetMapping("/getRwAndYhAndFxCount")
    public AjaxResult getRwAndYhAndFxCount() {
        List list = new ArrayList();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        Integer ywcCount = this.preventionCheckTaskConfigMapper.queryYwcCount();
        Integer sjCount = this.preventionCheckTaskConfigMapper.querySjCount();
        Integer hiddenCount = this.preventionHiddenRegisterMapper.queryHiddenCount();
        Integer hiddenZgCount = this.preventionHiddenRegisterMapper.queryHiddenZgCount();
        // B
        PreventionCheckTaskConfigCountVO vo2 = new PreventionCheckTaskConfigCountVO();
        if (0 == sjCount) {
            vo2.setCount("100.00%");
        } else {
            vo2.setCount(prcentageUtils.percent(ywcCount, sjCount));
        }
        vo2.setName("排查任务完成率");
        list.add(vo2);
        // C
        PreventionCheckTaskConfigCountVO vo3 = new PreventionCheckTaskConfigCountVO();
        if (0 == hiddenCount) {
            vo3.setCount("100.00%");
        } else {
            vo3.setCount(prcentageUtils.percent(hiddenZgCount, hiddenCount));
        }
        vo3.setName("隐患整改率");
        list.add(vo3);
        return AjaxResult.success(list);
    }


    @GetMapping("/countSecurityUnit")
    public AjaxResult countSecurityUnit() {
        List<Map<String, Object>> mapList = new ArrayList<>();
        PrcentageUtils prcentageUtils = new PrcentageUtils();
        List<PreventionDeviceFsVO> allACount = preventionDeviceService.queryAllACount("", "", "");
        List<PreventionDeviceFsVO> aCount = preventionDeviceService.queryACount("", "", "");
        Map<String, Object> map = new HashMap<>();
        if (0 == allACount.size()) {
            map.put("aCountRate", "100.00%");
        } else {
            map.put("aCountRate", prcentageUtils.percent(aCount.size(), allACount.size()));
        }
        List<PreventionDeviceVO> preventionDeviceVOS = preventionDeviceService.queryByPage(new PreventionDevice());
        Integer unit = 0;
        Integer event = 0;
        Integer control = 0;
        Integer task = 0;
        for (PreventionDeviceVO preventionDeviceVO : preventionDeviceVOS) {
            unit += preventionSecurityRiskService.countUnit(preventionDeviceVO.getId());
            event += preventionSecurityRiskService.countEvent(preventionDeviceVO.getId());
            control += preventionSecurityRiskService.countControl(preventionDeviceVO.getId());
            task += preventionSecurityRiskService.countTask(preventionDeviceVO.getId());
        }
        // 获取分析单元数
        map.put("unit", unit);
        // 获取风险事件数
        map.put("event", event);
        // 获取管控措施数
        map.put("control", control);
        // 获取排查任务数量
        map.put("task", task);
        // 分析单元管控措施小于5的
        map.put("aCount", CollUtil.isEmpty(aCount) ? 0 : aCount.size());
        // 获取重大危险源数
        Integer dangerCount = preventionDeviceService.listByDangerName();
        map.put("dangerCount", dangerCount);
        map.put("dangerCountAll", dangerCount);
        // 排查任务周期为一小时的
        Integer taskCount = preventionSecurityRiskMapper.queryByUnit();
        map.put("taskCount", taskCount);
        mapList.add(map);
        return AjaxResult.success(mapList);
    }


    /**
     * 三维统计_企业总人数_1、2号库区在岗人数_证照临期数_设备告警数_待排查任务数_隐患总数_待整改隐患数_隐患超期数_即将超时任务数
     */
    @GetMapping("/toCountQyKqZzSbRwYh")
    public AjaxResult toCountQyKqZzSbRwYh() {
        Map<String, Object> map = new HashMap<>();
        String qys = enterpriseBasicMapper.getQys();
        int alert = appCreateJobBillService.countCreateJobBill(YnStatusEnum.N.getCode());
        int zzs = securityStaffCertificateRecordMapper.getZzs();
        int sbs = sysMonitorMapper.getSbc();
        int dpcs = preventionPlanTaskMapper.getDpcs();
        int yhzs = preventionHiddenRegisterMapper.queryHiddenCountTemp();
        int dzgs = preventionHiddenRegisterMapper.queryHiddenZgCountTemp();
        int yhcqs = preventionHiddenRegisterMapper.getYhcqs();
        int jjcss = preventionPlanTaskMapper.getJjcss();

        // 库区人员统计
        int person = 0;
        try {
            Object personCount = PersonPosition.count();
            if (personCount != null) {
                JSONObject jsonObject = new JSONObject(personCount);
                JSONArray dataArray = jsonObject.getJSONArray("data");
                if (dataArray != null && !dataArray.isEmpty()) {
                    for (Object item : dataArray) {
                        JSONObject itemJson = new JSONObject(item);
                        if ("1".equals(itemJson.getStr("id"))) {
                            person = itemJson.getInt("count", 0);
                            break;
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("获取库区人员统计异常", e);
            person = 0;
        }
        map.put("库区在线总人数",person);
        map.put("今日作业数", alert);
        map.put("证照临期数", zzs);
        map.put("设备告警数", sbs);
        map.put("待排查任务数", dpcs);
        map.put("隐患总数", yhzs);
        map.put("隐患超期数", dzgs);
        map.put("待整改隐患数", yhcqs);
        map.put("超时任务数", jjcss);
        return AjaxResult.success(map);
    }

    private List<PreventionCheckTaskConfigCountVO> getToCountDeptAll() {
        List<PreventionCheckTaskConfigCountVO> arrayList = preventionHiddenRegisterService.getToCountDeptAll();
        if (CollectionUtils.isEmpty(arrayList)) {
            AjaxResult.error("601", "暂无数据");
        }
        return arrayList;
    }

    private List<PreventionCheckTaskConfigCountVO> checkAllSituation(String checkUserName) {
        List<PreventionCheckTaskConfigCountVO> arrayList = new ArrayList<>();
        List<PreventionCheckTaskCountStateVO> deptGroupBy = preventionCheckTaskConfigService.getCheckAllSituation(checkUserName);
        if (!CollectionUtils.isEmpty(deptGroupBy)) {
            for (PreventionCheckTaskCountStateVO stateVO : deptGroupBy) {
                PreventionCheckTaskConfigCountVO taskConfigCountVO = new PreventionCheckTaskConfigCountVO();
                taskConfigCountVO.setName(stateVO.getName());
                taskConfigCountVO.setCount(stateVO.getCount());
                arrayList.add(taskConfigCountVO);
            }
        }
        return arrayList;
    }

    private List<PreventionCheckTaskConfigCountVO> checkAll(String checkUserName) {
        List<PreventionCheckTaskConfigCountVO> arrayList = new ArrayList<>();
        List<PreventionCheckTaskCountStateVO> deptGroupBy = preventionCheckTaskConfigService.getDeptGroupByList(checkUserName);
        if (!CollectionUtils.isEmpty(deptGroupBy)) {
            for (PreventionCheckTaskCountStateVO stateVO : deptGroupBy) {
                PreventionCheckTaskConfigCountVO taskConfigCountVO = new PreventionCheckTaskConfigCountVO();
                taskConfigCountVO.setName(stateVO.getName());
                taskConfigCountVO.setCount(stateVO.getCount());
                arrayList.add(taskConfigCountVO);
            }
        }
        return arrayList;
    }

    /**
     * 顶部统计条排列次序：待排查任务、已排查任务、已超时任务,待审核隐患、待整改隐患、待复核隐患、已验收隐患，隐患排查预警、隐患治理预警、本周IMEI码
     * 已超时任务、已验收隐患，隐患排查预警、隐患治理预警显示格式，上标表示本周增加的数量，
     * 已超时任务可以点击进入显示已超时任务列表，且表单里可以按时间段、装置、单元名称，排查人员查询
     * @return
     */
    @GetMapping("/countTop")
    public AjaxResult countTop() {
        // 待排查任务
        long dpc = preventionCheckTaskMapper.getTaskByState("待排查",null, null,null);
        // 已排查任务
        long ypc = preventionCheckTaskMapper.getTaskByState("已排查",null, null,null);
        // 已超时任务
        long ycs = preventionCheckTaskMapper.getTaskByState("已超时",null, null,null);
        // 待审核隐患
        long dsh = preventionHiddenRegisterMapper.countAll("待审核",null, null, null);
        // 待整改隐患
        long dzg = preventionHiddenRegisterMapper.countAll("待整改",null, null, null);
        // 待复核隐患
        long dfh = preventionHiddenRegisterMapper.countAll("待复核",null, null, null);
        // 已验收隐患
        long ywc = preventionHiddenRegisterMapper.countAll("已完成",null, null, null);
        // 隐患排查、隐患治理
        // 隐患排查预警
        long yhpc = preventionAlertMapper.countAll("隐患排查",null,null,null);
        // 隐患治理预警
        long yhzl = preventionAlertMapper.countAll("隐患治理",null,null,null);
        String startTime = DateUtil.beginOfWeek(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
        String endTime = DateUtil.endOfWeek(DateUtil.date()).toString("yyyy-MM-dd HH:mm:ss");
        // 本周IMEI码
        Integer imei = preventionCheckTaskConfigMapper.countImei(null,startTime, endTime);
        // 本周已超时任务
        long bzycsrw = preventionCheckTaskMapper.getTaskByState("已超时",startTime, endTime,null);
        // 本周已验收隐患
        long bzyacyh = preventionHiddenRegisterMapper.countAll("已完成",startTime, endTime, null);
        // 本周隐患排查预警
        long bzyhpc = preventionAlertMapper.countAll("隐患排查",startTime, endTime,null);
        // 本周隐患治理预警
        long bzyhyj = preventionAlertMapper.countAll("隐患治理",startTime, endTime,null);
        Map<String,Object> map = new HashMap<>();
        map.put("待排查任务",dpc);
        map.put("已排查任务",ypc);
        map.put("已超时任务",ycs);
        map.put("待审核隐患",dsh);
        map.put("待整改隐患",dzg);
        map.put("待复核隐患",dfh);
        map.put("已验收隐患",ywc);
        map.put("隐患排查预警",yhpc);
        map.put("隐患治理预警",yhzl);
        map.put("本周IMEI码",imei);
        map.put("本周已超时任务",bzycsrw);
        map.put("本周已验收隐患",bzyacyh);
        map.put("本周隐患排查预警",bzyhpc);
        map.put("本周隐患治理预警",bzyhyj);
        return AjaxResult.success(map);
    }

    @GetMapping("/getCheckTaskByState")
    public TableDataInfo getCheckTaskByState(String device,String unit,String userName,String startTime,String endTime) {
        startPage();
        List<PreventionCheckTaskVO> preventionCheckTaskVOS = preventionCheckTaskMapper.getCheckTaskByState(device,unit,userName,startTime,endTime);
        return getDataTable(preventionCheckTaskVOS);
    }

    /**
     * 排查任务情况，以周为周期显示排查任务情况，默认显示最近8周排查任务数，排查完成率（任务数以柱状表示，排查完成率以折线图表示），并且可以根据岗位筛查，可以选择查询开始的周*
     * @return
     */
    @GetMapping("/countCheckTaskWeek")
    public AjaxResult countCheckTaskWeek(Integer week,Integer year) {
        Map<String,Map<String,Object>> map = new HashMap<>();
        Integer c = 0;
        for (int i = 0; i < 8; i++) {
            if (i == 0) {
                c = week;
            } else {
                c = week - i;
            }
            // 开始时间
            String startTime = getStartDayOfWeekNo(year, c);
            // 结束时间
            String endTime = getEndDayOfWeekNo(year, c);
            // 已排查任务
            long ypc = preventionCheckTaskMapper.getTaskByState("已排查",startTime, endTime,null);
            // 已超时任务
            long ycs = preventionCheckTaskMapper.getTaskByState("已超时",startTime, endTime,null);
            Map<String,Object> objectMap = new HashMap<>();
            objectMap.put("task",ypc + ycs);
            if (ypc + ycs == 0) {
                objectMap.put("rate","100");
            } else {
                Double dd = ypc + 0.00;
                Double cc = (ypc + ycs) + 0.00;
                DecimalFormat df = new DecimalFormat("##0.00");
                objectMap.put("rate",df.format(dd / cc * 100));
            }
            map.put(c.toString(),objectMap);
        }
        return AjaxResult.success(map);
    }

    public String getStartDayOfWeekNo(int year,int weekNo){
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);
        return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +
                cal.get(Calendar.DAY_OF_MONTH) + " 00:00:00";
    }
    public String getEndDayOfWeekNo(int year,int weekNo){
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);
        cal.add(Calendar.DAY_OF_WEEK, 6);
        return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +
                cal.get(Calendar.DAY_OF_MONTH) + " 23:59:59";
    }
    private Calendar getCalendarFormYear(int year){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.YEAR, year);
        return cal;
    }
    /**
     * 任务排查分布，默认显示全部单元的已排查、待排查、已超时任务数及占比，可以根据单元名称筛选*
     * @param unit
     * @return
     */
    @GetMapping("/countCheckTaskByUnit")
    public AjaxResult countCheckTaskByUnit(String unit) {
        // 待排查任务
        long dpc = preventionCheckTaskMapper.getTaskByState("待排查",null, null,unit);
        // 已排查任务
        long ypc = preventionCheckTaskMapper.getTaskByState("已排查",null, null,unit);
        // 已超时任务
        long ycs = preventionCheckTaskMapper.getTaskByState("已超时",null, null,unit);
        Map<String,Object> map = new HashMap<>();
        map.put("待排查",dpc);
        map.put("已排查",ypc);
        map.put("已超时",ycs);
        List<String> list = preventionSecurityRiskMapper.countUnit(null);
        map.put("unitList",list);
        return AjaxResult.success(map);
    }

    /**
     * 隐患整改情况，以饼图形式展示待审核、待整改、待复核、已验收各环节的数量及占比。*
     * @return
     */
    @GetMapping("/countHiddenByState")
    public AjaxResult countHiddenByState() {
        // 待审核隐患
        long dsh = preventionHiddenRegisterMapper.countAll("待审核",null, null, null);
        // 待整改隐患
        long dzg = preventionHiddenRegisterMapper.countAll("待整改",null, null, null);
        // 待复核隐患
        long dfh = preventionHiddenRegisterMapper.countAll("待复核",null, null, null);
        // 已验收隐患
        long ywc = preventionHiddenRegisterMapper.countAll("已完成",null, null, null);
        Map<String,Object> map = new HashMap<>();
        map.put("待审核",dsh);
        map.put("待整改",dzg);
        map.put("待复核",dfh);
        map.put("已验收",ywc);
        return AjaxResult.success(map);
    }

    /**
     * 隐患整改统计，按单元位置查询隐患数量，可以按时间筛选，以柱状显示，柱状态用颜色区分已完成、待整改及待完成数量*
     * @return
     */
    @GetMapping("/countHiddenByDevice")
    public AjaxResult countHiddenByDevice(String device,String startTime,String endTime) {
        List<PreventionDevice> preventionDevices = preventionDeviceService.queryList(new PreventionDevice());
        PreventionDevice preventionDevice = preventionDevices.stream().filter(var -> var.getDeviceName().equals(device)).collect(Collectors.toList()).stream().findFirst().orElse(new PreventionDevice());
        // 待审核隐患
        long dsh = preventionHiddenRegisterMapper.countAll("待审核",startTime, endTime,preventionDevice.getId());
        // 待整改隐患
        long dzg = preventionHiddenRegisterMapper.countAll("待整改",startTime, endTime,preventionDevice.getId());
        // 待复核隐患
        long dfh = preventionHiddenRegisterMapper.countAll("待复核",startTime, endTime,preventionDevice.getId());
        // 已验收隐患
        long ywc = preventionHiddenRegisterMapper.countAll("已完成",startTime, endTime,preventionDevice.getId());
        Map<String,Object> map = new HashMap<>();
        map.put("待审核",dsh);
        map.put("待整改",dzg);
        map.put("待复核",dfh);
        map.put("已验收",ywc);
        map.put("allDeviceName",preventionDevices);
        return AjaxResult.success(map);
    }

    /**
     * 预警分析统计，可以按时间区间查询隐患排查预警、隐患治理预警量，以折线图显示*
     * @return
     */
    @GetMapping("/countHiddenByDeviceAlert")
    public AjaxResult countHiddenByDevice(String year) {
        String[] arr = new String[]{"01","02","03","04","05","06","07","08","09","10","11","12"};
        Map<String,Map<String,Long>> map = new HashedMap();
        for (int i = 0; i < arr.length; i++) {
            // 隐患排查预警
            long bzyhpc = preventionAlertMapper.countAll("隐患排查",null,null,year + "-" + arr[i]);
            // 隐患治理预警
            long bzyhyj = preventionAlertMapper.countAll("隐患治理",null,null,year + "-" + arr[i]);
            Map<String,Long> m = new HashedMap();
            m.put("yhpc",bzyhpc);
            m.put("yhzl",bzyhyj);
            map.put(arr[i],m);
        }
        return AjaxResult.success(map);
    }
}

